package repository

import (
	"energy-amiot-platform/model/dbspo"

	"gorm.io/gorm"
)

var (
	COMPANY companyRepository
)

type companyRepository struct {
}

func (p *companyRepository) Exist(db *gorm.DB, key uint64) (*gorm.DB, bool) {
	var count int64
	tx := db.Model(&dbspo.Company{}).Where("id=?", key).Count(&count)
	return tx, count > 0
}

func (p *companyRepository) ExistWithName(db *gorm.DB, name string) (*gorm.DB, bool) {
	var count int64
	tx := db.Model(&dbspo.Company{}).Where("name=?", name).Count(&count)
	return tx, count > 0
}

func (p *companyRepository) Create(db *gorm.DB, company *dbspo.Company) *gorm.DB {
	return db.Create(company)
}

func (p *companyRepository) DeleteById(db *gorm.DB, id uint64) *gorm.DB {
	return db.Model(&dbspo.Company{}).Delete("id=?", id)
}
